import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/login.vue'
import SignUp from '../views/SignUp.vue'
// import Home from '../views/Home.vue'
import User from '../components/User.vue'
import AddUser from '../components/AddUser.vue'
import About from '../components/About.vue'
// import Form from '../components/Form.vue'
import LiuYan from '../views/LiuYan.vue'
import ZhiWei from '../components/ZhiWei.vue'
import AddZhiWei from '../components/AddZhiWei.vue'
import BuMen from '../components/BuMen.vue'
import AddBuMen from '../components/AddBuMen.vue'
import YuanGong from '../components/YuanGong.vue'
import AddYuanGOng from '../components/AddYuanGong.vue'
import File from '../components/File.vue'
import AddFile from '../components/AddFile.vue'
import Salary from '../components/Salary.vue'
import GongGao from '../components/GongGao.vue'
import AddGongGao from '../components/AddGongGao.vue'
import Leave from '../components/Leave.vue'
import AddLeave from '../components/AddLeave.vue'
import LeaveApproval from '../components/LeaveApproval.vue'


Vue.use(VueRouter)

const routes = [{
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: '/signup',
    name: 'signup',
    component: SignUp

  },
  {
    path: '/',
    name: 'home',
    component: () =>
      import ('../views/home.vue'),
    meta: {
      title: "首页"
    },
    children: [{
        path: '/about',
        name: "关于",
        component: About,
        meta: {
          title: "欢迎"
        },
      }, {
        path: '/user',
        name: "用户查询",
        component: User,
        meta: {
          title: "用户查询"
        },

      }, {
        path: '/adduser',
        name: "添加用户",
        component: AddUser,
        meta: {
          title: "添加用户"
        },

      },
      {
        path: '/zhiwei',
        name: "职位查询",
        component: ZhiWei,
        meta: {
          title: "职位查询"
        },

      }, {
        path: '/addzhiwei',
        name: "添加职位",
        component: AddZhiWei,
        meta: {
          title: "添加职位"
        },

      }, {
        path: '/bumen',
        name: "部门查询",
        component: BuMen,
        meta: {
          title: "部门查询"
        },

      }, {
        path: '/addbumen',
        name: "添加部门",
        component: AddBuMen,
        meta: {
          title: "添加部门"
        },

      }, {
        path: '/yuangong',
        name: "员工查询",
        component: YuanGong,
        meta: {
          title: "员工查询"
        },
      }, {
        path: '/employee',
        name: "职位与薪资",
        component: () =>
          import ('../components/Employee.vue'),
        meta: {
          title: "职位与薪资"
        },
      }, {
        path: '/signInInf',
        name: "考勤记录",
        component: () =>
          import ('../components/SignInInf.vue'),
        meta: {
          title: "考勤记录"
        },
      }, {
        path: '/addyuangong',
        name: "添加员工",
        component: AddYuanGOng,
        meta: {
          title: "添加员工"
        },
      },
      {
        path: '/file',
        name: "文件查询",
        component: File,
        meta: {
          title: "文件查询"
        },

      }, {
        path: '/addFile',
        name: "添加文件",
        component: AddFile,
        meta: {
          title: "添加文件"
        },

      },
      {
        path: '/gonggao',
        name: "公告查询",
        component: GongGao,
        meta: {
          title: "公告查询"
        },

      }, {
        path: '/addGongGao',
        name: "添加公告",
        component: AddGongGao,
        meta: {
          title: "添加公告"
        },

      }, {
        path: '/salary',
        name: "薪资管理",
        component: Salary,
        meta: {
          title: "薪资管理"
        },

      },
      {
        path: '/liuyan',
        name: "留言",
        component: LiuYan,
        meta: {
          title: "留言"
        },
      },

      {
        path: '/leave',
        name: "请假查询",
        component: Leave,
        meta: {
          title: "请假查询"
        },
      },
      {
        path: '/addLeave',
        name: "请假申请",
        component: AddLeave,
        meta: {
          title: "请假申请"
        },
      },
      {
        path: '/leaveApproval',
        name: "请假审批",
        component: LeaveApproval,
        meta: {
          title: "请假审批"
        },
      },
      {
        path: '/employeeInf',
        name: '员工信息',
        component: () =>
          import ('../components/employeeInf'),
        meta: {
          title: '员工信息'
        },
      }
    ]
  },

]

const router = new VueRouter({
  mode: 'history',
  // base: process.env.BASE_URL,
  routes
})

// 全局前置守卫
router.beforeEach(function(to, from, next) {

  const token = sessionStorage.getItem('token')
  if (to.name !== 'login' && !token) {
    next('/login')
  } else {
    next()
  }


})



export default router